/*
 *  Copyright 2003 by Spectrum Digital Incorporated.
 *  All rights reserved. Property of Spectrum Digital Incorporated.
 */
 
/*
 *  ======== evmdm642_led.c ========
 *  LED module for the EVMDM642
 */
 
#include <csl.h>

#include "evmdm642.h"
#include "evmdm642_led.h"

static Int16 ledstate;

void EVMDM642_LED_init()
{
    /* Turn all LEDs off */
    ledstate = 0xff;
    EVMDM642_rset(EVMDM642_LED, ledstate);
}

void EVMDM642_LED_off(Uint32 ledNum)
{
    /* Check bounds for ledNum */
    if (ledNum >= 8)
        return;
       
    /* Clear the LED bit */
    ledstate |= 1 << ledNum;
    EVMDM642_rset(EVMDM642_LED, ledstate);
}

void EVMDM642_LED_on(Uint32 ledNum)
{
    /* Check bounds for ledNum */
    if (ledNum >= 8)
        return;
        
    /* Set the LED bit */
    ledstate &= ~(1 << ledNum);
    EVMDM642_rset(EVMDM642_LED, ledstate);
}

void EVMDM642_LED_toggle(Uint32 ledNum)
{
    /* Check bounds for ledNum */
    if (ledNum >= 8)
        return;
        
    /* Toggle the LED bit */
    if ((EVMDM642_rget(EVMDM642_LED) & (1 << ledNum)) != 0)
        EVMDM642_LED_on(ledNum);
    else
        EVMDM642_LED_off(ledNum);
}


